package com.effectivcrm.controller


import javax.validation.Valid;
import com.effectivcrm.domain.Opportunity
import com.effectivcrm.service.OpportunityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1/opportunity")
class OpportunityRestController {

	@Autowired
	OpportunityService service;
	
	
	@RequestMapping( method=RequestMethod.POST )
	def create( @RequestBody @Valid Opportunity opportunity ){
		return service.create(opportunity);
	}
	
	@RequestMapping(value="/{id}" , method=RequestMethod.GET )
	def findOne( @PathVariable String id){
		return service.findOne(id);
	}
	
	@RequestMapping( method=RequestMethod.PUT )
	def update(@RequestBody @Valid Opportunity opportunity) {
		return service.update(opportunity);
	}
	
	@RequestMapping(value="/{id}", method=RequestMethod.DELETE )
	def delete(@PathVariable String id){
		return service.delete(id);
	}
	
	@RequestMapping(value = "/list/{viewName}", method=RequestMethod.GET )
	def list( @PathVariable String viewName){
		return service.findAll(viewName);
	}
	
}
